

#include <iostream>
//using std::cout;
//using std::endl;
using namespace std;

struct BTree
{
	int val;
	BTree* left;
	BTree* right;
};

int BTreeSize(BTree* root)
{
	if (nullptr == root)
		return 0;

	return BTreeSize(root->left) + BTreeSize(root->right) + 1;
}

int BTreeLeafSize(BTree* root)
{
	if (nullptr == root)
		return 0;

	if (nullptr == root->left && nullptr == root->right)
		return 1;

	int left = BTreeLeafSize(root->left);
	int right = BTreeLeafSize(root->right);

	return left+right;
}

BTree* BuyNode(int x)
{
	BTree* node = new BTree;

	node->val = x;
	node->left = nullptr;
	node->right = nullptr;

	return node;
}

int main()
{
	BTree* n1 = BuyNode(1);
	BTree* n2 = BuyNode(2);
	BTree* n3 = BuyNode(3);
	BTree* n4 = BuyNode(4);
	BTree* n5 = BuyNode(5);
	BTree* n6 = BuyNode(6);
	BTree* n7 = BuyNode(7);
	
	n1->left = n2, n1->right = n3;
	n2->left = n4, n2->right = n5;
	n3->left = n6, n3->right = n7;
	
	cout << BTreeSize(n1) << endl;
	cout << BTreeLeafSize(n1) << endl;


	delete n1;
	delete n2;
	delete n3;
	delete n4;
	delete n5;
	delete n6;

	return 0;
}